package com.cmwa.scbp.sys.organization.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.cmwa.scbp.sys.organization.dao.CompanyDao;
import com.cmwa.scbp.sys.organization.dao.OrganizationDao;
import com.cmwa.scbp.sys.organization.entity.CompanyVo;
import com.cmwa.scbp.sys.organization.service.CompanyService;
import com.cmwa.scbp.utils.SessionUtils;

@Service
public class CompanyServiceImpl implements CompanyService {
	
	@Resource
	private CompanyDao companyDao;
	@Resource
	private OrganizationDao organizationDao;

	@Override
	public List<CompanyVo> queryMatchCompany(CompanyVo companyVo) {
		return companyDao.queryMatchCompany(companyVo);
	}

	@Override
	public boolean checkRepeatCompanyFullName(String orgId, String companyFullName) {
		int count = companyDao.countByCompanyFullName(orgId, companyFullName);
		return count > 0;
	}

	@Override
	public void modifyOutOrgExt(CompanyVo org) {
		String orgId = org.getId();
		if(StringUtils.isNotBlank(orgId)) {
			
			org.setId(orgId);
			
			// 1、修改机构表
			organizationDao.updateOrgName(orgId, org.getCompanyName());
			// 2、修改拓展表
			org.setModifyId(SessionUtils.getEmployee().getID());
			companyDao.updateCompanyInfo(org);
		}
	}

	@Override
	public CompanyVo findCompanyById(String firmId) {
		return companyDao.findCompanyById(firmId);
	}
	
}
